package com.health.controller;

import com.health.common.Result;
import com.health.entity.Meal;
import com.health.entity.pojo.PageData;
import com.health.entity.pojo.dto.QueryHospitalDTO;
import com.health.entity.pojo.dto.QueryMealDTO;
import com.health.entity.pojo.vo.HospitalVO;
import com.health.entity.pojo.vo.MealVO;
import com.health.service.IHospitalService;
import com.health.service.IMealService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 套餐表 前端控制器
 * </p>
 *
 * @author sanchuan
 * @since 2023-04-18
 */
@Api(tags = "套餐管理")
@RestController
@RequestMapping("/meal")
public class MealController extends BaseController{
    @Autowired
    private IMealService mealService;

    @Autowired
    private IHospitalService hospitalService;

    @ApiOperation("分页+条件查询套餐")
    @PostMapping("/listMealPage/{pageNum}/{pageSize}")
    public Result listMealPage(@PathVariable("pageNum") Integer pageNum,
                                       @PathVariable("pageSize") Integer pageSize,
                                       @RequestBody QueryMealDTO queryMealDTO){
       return this.dataResult(mealService.listMealPage(pageNum,pageSize,queryMealDTO));
    }

    @ApiOperation("修改套餐上架状态")
    @PostMapping("/changeMedicalShelves/{isShelves}/{id}")
    public Result<String> changeMedicalShelves(@PathVariable("isShelves") boolean isShelves, @PathVariable("id") Integer id){
        Boolean result = mealService.changeMedicalShelves(isShelves, id);
        return this.dataResult(result);
    }

    @ApiOperation("批量修改套餐上架状态")
    @PostMapping("/changeMedicalShelvesMulti/{isShelves}")
    public Result<String> changeMedicalShelvesMulti(@PathVariable("isShelves") boolean isShelves, @RequestBody List<Integer> ids){
        Boolean result = mealService.changeMedicalShelvesMulti(isShelves,ids);
        return this.dataResult(result);
    }

    @ApiOperation("批量删除套餐")
    @DeleteMapping("/deleteMedicalShelvesMulti")
    public Result<String> deleteMedicalShelvesMulti(@RequestBody List<Integer> ids){
        System.out.println(ids);
        Boolean b = mealService.removeBatchByIds(ids);
        return this.dataResult(b);
    }

    @ApiOperation("获取医院列表")
    @GetMapping("/getHospitals")
    public Result<HospitalVO> getHospitals(){
        return this.dataResult(hospitalService.getHospitals());
    }

    @ApiOperation("添加套餐")
    @PostMapping("/addMedical")
    public Result<String> addMedical(@RequestBody Meal meal){
        return this.dataResult(mealService.saveOrUpdate(meal));
    }

    @ApiOperation("根据ID获得套餐详情")
    @GetMapping("/getMedicalDetailsById/{id}")
    public Result<Meal> getMedicalDetailsById(@PathVariable Integer id){
        return this.dataResult(mealService.getById(id));
    }
}
